<?php
session_start();
require_once("config.php");
require_once("Smarty-2.6.18/libs/Smarty.class.php");
require_once("Database.php");
require_once("Info.php");
require_once("Artist.php");
require_once("TagCloud.php");
require_once("Tag.php");
require_once("Lastfm.php");
require_once("Lineup.php");
require_once("VenueList.php");
require_once("Input.php");
require_once("ArtistMatchItem.php");

$smarty = new Smarty();
$smarty->compile_check = true;
$smarty->debugging = false;

$tagCloud = new TagCloud();
$tags = $tagCloud->getCloud();
$smarty->assign("tags", $tags);
$venueList = new VenueList();

/*
$venues_festivals = $venueList->getFestivals();
$venues_gigs = $venueList->getGigs();

$smarty->assign("venues_festivals", $venues_festivals);
$smarty->assign("venues_gigs", $venues_gigs);
$lineup = Venue::parse($_GET['venue_id']);
*/

if(!empty($_GET['location'])) {
    $lineup = Lineup::getEvents($_GET['location']);
}

// Input from the user
if(!empty($_GET['custom_tag'])) {
    $userArtists = Input::getTagTopArtists($_GET['custom_tag']); 
} elseif(!empty($_GET['username'])) {
    $userArtists = Input::getUserTopArtists($_GET['username']); 
} elseif(!empty($_GET['tag'])) {
    $userArtists = Input::getTagTopArtists($_GET['tag']); 
} 

if (is_array($userArtists) && is_array($lineup)) {
    $resultLineup = Lastfm::match($lineup, $userArtists, $_GET['tag']);
    $smarty->assign("cacheArtists", $_SESSION[$_GET['location']]);
    $smarty->assign("resultLineup", $resultLineup);
    $smarty->assign("input", $_GET['tag']);
}

$smarty->display('index.tpl');


?>